PHP

How to implement an interface into multiple classes in PHP | PHP programs

How to implement an interface into multiple classes in PHP | PHP programs

How to implement an interface into multiple classes in PHP | PHP programs

We will create an interface that contains the declaration of functions and then we will implement the interface into multiple classes with function definitions.

<?php


interface Inf
{
    public function fun();
}

class Sample1 implements Inf
{
    public function fun()
    {
        printf("Sample1::fun() called<br>");
    }
}

class Sample2 implements Inf
{
    public function fun()
    {
        printf("Sample2::fun() called<br>");
    }
}

class Sample3 implements Inf
{
    public function fun()
    {
        printf("Sample3::fun() called<br>");
    }
}

$obj1 = new Sample1();
$obj2 = new Sample2();
$obj3 = new Sample3();

$obj1->fun();
$obj2->fun();
$obj3->fun();
?>
TutorialsLink Curator

This is an official account managed by the team TutorialsLink Community